<?php
    ob_start();
    define('ABSOLUTE_SERVER_DOCUMENT_ROOT','../../');
    if(file_exists('../../../definitions.inc.php')) include_once('../../../definitions.inc.php');
    include('../../session.inc');
    require_once('../../funct.inc');
    require_once('invoice.inc');
    //--------------------MODUL LOGS--------------------------------------
    if (file_exists("../logs/logs.inc"))
	require_once("../logs/logs.inc");
    //--------------------------------------------------------------------
    include '../../color_style.php';
    include '../../'.LANGUAGE;

    if(!GetAdminID($ID)){echo LOGIN_ERR;exit;}
    if(!Right_Check(2)){header('Location:../../error.php');exit;}

    include '../../../plugins/order/classOrderService.inc.php';
    
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <title>METIS ADMIN</title>
    <?php echo '<meta http-equiv="Content-Type" content="text/html; charset='._CHARSET_.';">'; ?>

    <?php include '../../html_style.php';?>

    <?php
        print "
            <script language=\"JavaScript\">
                <!--
                    function OpenPage(id, count){
                        var ComletPageName= \"".ABSOLUTE_SERVER_DOCUMENT_ROOT."show_product_detail.php\" + \"?ID=\" + id + \"&amp;Count=\" + count;
                        window.close(\"ShopBasketProductDetail\");
                        window.open(ComletPageName,\"ShopBasketProductDetail\",\"width=700px,height=300px,location=no,directories=no,menubar=no,resizeable=yes,status=no,toolbar=no,scrollbars=yes\");
                    }
                //-->
            </script>
        ";
    ?>

</head>
<?php

print "<body bgcolor=\"".Background_Color."\">";

require_once('../../../classDB.inc.php');
require_once('../../functs.inc');
do
{
    $_DB = new classDB();
    if (!$_DB->open()){echo OPEN_DB_ERR; break;}

    if($_REQUEST["PageQuanter"]=="")
       $PageNo=$_REQUEST["PageNo"];
    else
       $PageNo=$_REQUEST["PageNo"]-1;

    if($PageNo=="" || $PageNo==-1) $PageNo=0;
 	//Definicie==========================================
    $ItemsOnPage = ITEMSONPAGE;
    $ShowQvantumPage = SHOWQVANTUMPAGE;
 	//===================================================
    $ActualQvantumPage=$_REQUEST["ActualQvantumPage"];
    if($ActualQvantumPage=="")$ActualQvantumPage = 0;

    $Logged_Admin   =$_SESSION['admin'];
    $index			=0;
    $roll_show		="/";

    $F_Surname      = $_REQUEST["F_Surname"];
    $F_Organisation = $_REQUEST["F_Organisation"];
    $F_ICO          = $_REQUEST["F_ICO"];

	

    $events=$_REQUEST["events"];
    switch($events) {
           case 'delete_order':	{
                     if ($_REQUEST["GrantDelete"]!="YES")
                        print"
                            <center>
                                <table border=\"1\" bgcolor=\"".BACKGROUND_IN_TABLE."\">
                                    <tr>
                                        <td>
											 <center>
                                             <b>".INV_NAOZAJ_ODSTRANIT."</b><br />
                                             <font color=\"red\">".INV_POZOR_FAKTURA_NEBUDE_PREMIESTNENA_DO_ARCHIVU."</font>
                                                 <form action=\"invoice.php\" target=\"place\" method=\"post\">
                                                    <input type=\"hidden\" value=\"".$ActualQvantumPage."\" name=\"ActualQvantumPage\" />
                                                    <input type=\"hidden\" name=\"events\" value=\"delete_order\" />
                                                    <input type=\"hidden\" name=\"Ch_ID\" value=\"".$_REQUEST["Ch_ID"]."\" />
                                                    <input type=\"hidden\" name=\"PageNo\" value=\"".$PageNo."\" />
                                                    <input type=\"hidden\" name=\"GrantDelete\" value=\"YES\" />
                                                    <input type=\"hidden\" value=\"".$F_Surname."\" name=\"F_Surname\" />
                                                    <input type=\"hidden\" value=\"".$F_Organisation."\" name=\"F_Organisation\" />
                                                    <input type=\"hidden\" value=\"".$F_ICO."\" name=\"F_ICO\" />
                                                    <input type=\"submit\" value='".INV_ANO_VYMAZAT."' style=\"width :100px; background-color: ".BUTTON_ON_OUT.";\"
                                                        onmouseover=\"this.style.backgroundColor='".BTN_IN_TABLE."'; this.style.fontWeight='bold';\";
                                                        onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
                                                </form>
                                            </center>
                                            <center>
                                                <form action=\"invoice.php\" target=\"place\" method=\"post\">
                                                    <input type=\"hidden\" value=\"".$ActualQvantumPage."\" name=\"ActualQvantumPage\" />
                                                    <input type=\"hidden\" name=\"events\" value=\"show_order\" />
                                                    <input type=\"hidden\" name=\"Ch_ID\" value=\"\" />
                                                    <input type=\"hidden\" name=\"PageNo\" value=\"".$PageNo."\" />
                                                    <input type=\"hidden\" value=\"".$F_Surname."\" name=\"F_Surname\" />
                                                    <input type=\"hidden\" value=\"".$F_Organisation."\" name=\"F_Organisation\" />
                                                    <input type=\"hidden\" value=\"".$F_ICO."\" name=\"F_ICO\" />
                                                    <input type=\"submit\" value='".INV_NIE_STORNO."' style=\"width :100px; background-color: ".BUTTON_ON_OUT.";\"
                                                        onmouseover=\"this.style.backgroundColor='".BTN_IN_TABLE."'; this.style.fontWeight='bold';\";
                                                        onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
                                                </form>
                                            </center>
                                        </td>
                                    </tr>
                                </table>
                            </center>
                        ";
                    else{
                        //---------------------------------------------------------------------
                      	 //-------------------------INVOICE_ARCHIVE-------------------------
                      	 /*
                      	 if (file_exists('invoice_archive/invoice_archive.inc')){
                          	 require_once 'invoice_archive/invoice_archive.inc';
                          	 Invoice_Archive_Insert($_REQUEST["Ch_ID"]);
                          	 //break;
                      	 }
                      	 //---------------------------------------------------------------------
                      	 */
                         ///-------------------Funkcia modulu LOGS--------------------------------
                         if (file_exists('../logs/logs.inc')){	                                             
                             Log_Insert(INV_FAKTURA_VYMAZANA.$_REQUEST["Ch_ID"], $ID);
                         }
                         ///----------------------------------------------------------------------
                         Invoice_Delete($_REQUEST["Ch_ID"]);
                    }
        }break;
        case 'show_order':  $roll_show = rutine_menu($_REQUEST["roll_show"],$_REQUEST["Ch_ID"]); break;
        default:break;
    }

    print("<center><b>".INV_ZOZNAM_AKTIVNYCH_FAKTUR."</b></center>");

    //**************************************************************************
    //
    //Zobrazenie komponentov pre vyhladavanie
    //
    //**************************************************************************

    if ($F_Surname=="" and $F_Organisation=="" and $F_ICO=="")
            print"
                <center>
                    <table style=\"border:1px solid black;\">
                        <tr>
                            <td>
                                <form action=\"invoice.php\" target=\"place\" method=\"post\">
                                    ".INV_PRIEZVISKO.":
                                    <input type=\"text\" name=\"F_Surname\">
                                    <input type=\"submit\" value=\"".INV_VYHLADAT."\" style=\"width :70px; background-color: ".BUTTON_ON_OUT.";\"
                                        onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                                        onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
                                </form>
                            </td>
                            <td>
                                <form action=\"invoice.php\" target=\"place\" method=\"post\">
                                    ".INV_ORGANIZaCIA.":
                                    <input type=\"text\" name=\"F_Organisation\">
                                    <input type=\"submit\" value=\"".INV_VYHLADAT."\" style=\"width :70px; background-color: ".BUTTON_ON_OUT.";\"
                                        onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                                        onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
                                </form>
                            </td>
                            <td>
                                <form action=\"invoice.php\" target=\"place\" method=\"post\">
                                    ".INV_ICO.":
                                    <input type=\"text\" name=\"F_ICO\">
                                    <input type=\"submit\" value=\"".INV_VYHLADAT."\" style=\"width :70px; background-color: ".BUTTON_ON_OUT.";\"
                                        onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                                        onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
                                </form>
                            </td>
                        </tr>
                    </table>
                </center>";
        else
            print"
                <center>
	                <table style=\"border:1px solid black;\">
	                    <tr>
	                        <td>
	                            <form action=\"invoice.php\" target=\"place\" method=\"post\">
	                                <input type=\"submit\" value=\"".INV_ZRUSIT_VYHLADAVANIE_ZOBRAZIT_VSETKY_ZAZNAMY."\" style=\"width=280px; background-color: ".BUTTON_ON_OUT.";\"
                                            onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                                            onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
	                            </form>
	                        </td>
	                    </tr>
	                </table>
                </center>";

    //**************************************************************************
    //
    //Vytvorenie menu pre vyber zobrazovanej stranky (rozdelenie zobrazovane hotovaru) - ulozene hore
    //
    //**************************************************************************

    if ($F_Surname!="") $sql_psel= "SELECT COUNT(*) FROM invoice_heads WHERE IH_Surname LIKE '%".$F_Surname."%'";
    if ($F_Organisation!="") $sql_psel= "SELECT COUNT(*) FROM invoice_heads WHERE IH_Organisation LIKE '%".$F_Organisation."%'";
    if ($F_ICO!="") $sql_psel= "SELECT COUNT(*) FROM invoice_heads WHERE IH_ICO='".$F_ICO."'";
    if ($F_Surname=="" and $F_Organisation=="" and $F_ICO=="")
            $sql_psel= "SELECT COUNT(*) FROM invoice_heads";
    $sql_array_adm = mysql_fetch_row(mysql_query($sql_psel));
    if($sql_array_adm[0]/$ItemsOnPage==($PageNo)) $PageNo--;
    if($sql_array_adm[0]/$ItemsOnPage<=$ActualQvantumPage) $ActualQvantumPage=$ActualQvantumPage-$ShowQvantumPage;

    if (($sql_array_adm[0])==0){
           print "<br><center><b>".INV_ZIADNY_ZAZNAM_NEBOL_NAJDENY."</b></center>";
           break;
      }
    do{
      if (($sql_array_adm[0]/$ItemsOnPage)<=1) break;
       print"<CENTER><table style=\"position:relative;  top:5px;\"><tr>";
	// Podmienka prvej >>>> --------------------------------------------------------------------
      if(($sql_array_adm[0]/$ItemsOnPage>$ShowQvantumPage) and ($ActualQvantumPage-$ShowQvantumPage>=0)){
             print "<td>";
             print "<form  action=\"invoice.php\" target=\"place\" method=\"post\">";
             if($sql_array_adm[0]>$ShowQvantumPage)
               print "<input type=\"submit\" value=\"<<<\"  style=\"width :50px; background-color: ".BUTTON_ON_OUT.";\"
                             onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                             onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />";
               $xxx=$ActualQvantumPage-$ShowQvantumPage;
               $Pagexxx=$xxx;
               print "<input type=\"hidden\" value=\"".$F_Surname."\" name=\"F_Surname\" />";
               print "<input type=\"hidden\" value=\"".$F_Organisation."\" name=\"F_Organisation\" />";
               print "<input type=\"hidden\" value=\"".$F_ICO."\" name=\"F_ICO\" />";
               print "<input type=\"hidden\" value=\"".$Pagexxx."\" name=\"PageNo\" />";
               print "<input type=\"hidden\" value=\"".$xxx."\" name=\"ActualQvantumPage\" />";
               print "<input type=\"hidden\" value=\"".$Path."\" name=\"path\" />";
               print "<input type=\"hidden\" value=\"".$Category_ID."\" name=\"ID\" />";
             print "</form>";
             print "</td>";
             }
 //--------------------------------------------------------------------------------------

//podmienka zvysnych stranok------------------------------------------------------------
          if(($ActualQvantumPage/$ShowQvantumPage)==floor(($sql_array_adm[0]/$ItemsOnPage)/$ShowQvantumPage))
              { if($sql_array_adm[0]%$ItemsOnPage==0)
                    $ShowActualQvantumPage=((($sql_array_adm[0]/$ItemsOnPage)%$ShowQvantumPage));
                else
                    $ShowActualQvantumPage=((($sql_array_adm[0]/$ItemsOnPage)%$ShowQvantumPage)+1);
              }
          else
              {$ShowActualQvantumPage=$ShowQvantumPage;}
 //---------------------------------------------------------------------------------------
      for($i=$ActualQvantumPage;$i<$ActualQvantumPage+$ShowActualQvantumPage;$i++)
    {
      print "<form  action=\"invoice.php\" target=\"place\" method=\"post\">";
          print "<td>";
          $Xi=$i+1;
          if($PageNo==$i)
            print "<input type=\"submit\" value=\"".$Xi."\" name=\"PageNo\"  style=\"width :50px; background-color: ".BUTTON_ON_OVER.";\" />";
          else
            print "<input type=\"submit\" value=\"".$Xi."\" name=\"PageNo\" style=\"width :25px; background-color: ".BUTTON_ON_OUT.";\"
                            onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                            onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\"
                        />";
          print "<input type=\"hidden\" value=\"".$F_Surname."\" name=\"F_Surname\" />";
          print "<input type=\"hidden\" value=\"".$F_Organisation."\" name=\"F_Organisation\" />";
          print "<input type=\"hidden\" value=\"".$F_ICO."\" name=\"F_ICO\" />";
          print "<input type=\"hidden\" value=\"1\" name=\"PageQuanter\" />";
          print "<input type=\"hidden\" value=\"".$ActualQvantumPage."\" name=\"ActualQvantumPage\" />";
          print "<input type=\"hidden\" value=\"".$Path."\" name=\"path\" />";
          print "<input type=\"hidden\" value=\"".$Category_ID."\" name=\"ID\" />";
          print "</form>";
          print "</td>";
    }

 //podmienka doprednej >>>> -----------------------------------------------------------
if(($sql_array_adm[0]/$ItemsOnPage) > ($ActualQvantumPage+$ShowQvantumPage)){
      print "<td>";
      print "<form  action=\"invoice.php\" target=\"place\" method=\"post\">";
      print "<input type=\"submit\" value=\">>>\"  style=\"width :50px; background-color: ".BUTTON_ON_OUT.";\"
              onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
              onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />";
      $xxx=$ActualQvantumPage+$ShowQvantumPage;
      $Pagexxx=$xxx;
      print "<input type=\"hidden\" value=\"".$F_Surname."\" name=\"F_Surname\" />";
      print "<input type=\"hidden\" value=\"".$F_Organisation."\" name=\"F_Organisation\" />";
      print "<input type=\"hidden\" value=\"".$F_ICO."\" name=\"F_ICO\" />";
      print "<input type=\"hidden\" value=\"".$Pagexxx."\" name=\"PageNo\" />";
      print "<input type=\"hidden\" value=\"".$xxx."\" name=\"ActualQvantumPage\" />";
      print "<input type=\"hidden\" value=\"".$Path."\" name=\"path\" />";
      print "<input type=\"hidden\" value=\"".$Category_ID."\" name=\"ID\" />";
    print "</form>";
    print "</td>";
    }
 //--------------------------------------------------------------------------------------
    print "</tr></table></center>";
    PrintLine();
    }while(false);

    print "<br>";
    //**************************************************************************
    //
    //Naplneneie obsahu stranky datami z databazy
    //
    //**************************************************************************
    //if($Category_ID==""){mysql_close(); break;}
        $From   = $PageNo*$ItemsOnPage;

        if ($F_Surname!="") $sql_psel= "SELECT * FROM invoice_heads WHERE IH_Surname LIKE '%".$F_Surname."%' ORDER BY ID DESC LIMIT ".$From.",".$ItemsOnPage;
            if ($F_Organisation!="") $sql_psel= "SELECT * FROM invoice_heads WHERE IH_Organisation LIKE '%".$F_Organisation."%'ORDER BY ID DESC LIMIT ".$From.",".$ItemsOnPage;
            if ($F_ICO!="") $sql_psel= "SELECT * FROM invoice_heads WHERE IH_ICO='".$F_ICO."'ORDER BY ID DESC LIMIT ".$From.",".$ItemsOnPage;
               if ($F_Surname=="" and $F_Organisation=="" and $F_ICO=="")
                $sql_psel=  "SELECT * FROM invoice_heads ORDER BY ID DESC LIMIT ".$From.",".$ItemsOnPage;

        $Product_source = mysql_query($sql_psel);
        $counter=0;
        while($sql_array_adm = mysql_fetch_object($Product_source))
        {
            $ShowAsDetails = is_roll($roll_show,$sql_array_adm->ID);
            if(!$ShowAsDetails)
            {
                    if(($counter%2))
                        print "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"98%\" bgcolor=\"".TR_BACKGOUND_COLOR_2."\">";
                    else
                        print "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"98%\" bgcolor=\"".TR_BACKGOUND_COLOR_1."\">";

                            //zobrazenie nazvu tovaru
                    print "<tr><td>";
                        if(($counter%2))
                            print "<table  border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" bgcolor=\"".TR_BACKGOUND_COLOR_2."\"><tr>";
                        else
                            print "<table  border=\"0\"cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" bgcolor=\"".TR_BACKGOUND_COLOR_1."\"><tr>";

                    print "<td align=\"left\">";
                      print("<b><font color=\"black\">".$sql_array_adm->IH_Prefix.$sql_array_adm->IH_No."</font color></b>");
                    print "</td>";
                    print "<td align=\"right\">";
                      print("<b><font color=\"".TEXT_COLOR_ORDER."\">(".$sql_array_adm->IH_Organisation." ".$sql_array_adm->IH_Name." ".$sql_array_adm->IH_Surname.")</font color></b>");
                      print "(".date(sttngs_DATE_FORMAT,strtotime($sql_array_adm->IH_Create)).")";
                    print "</td>";
                    print "</tr></table></td>";

                    print "<td align=\"right\" width=\"63px\">";
                          print "<form action=\"invoice.php\" target=\"place\" method=\"post\">";
                            print "<input type=\"hidden\" value=\"".$ActualQvantumPage."\" name=\"ActualQvantumPage\" />";
                            print "<input type=\"hidden\" name=\"events\" value=\"show_order\" />";
                            print "<input type=\"hidden\" name=\"roll_show\" value=\"".$roll_show."\" />";
                            print "<input type=\"hidden\" name=\"Ch_ID\" value=\"".$sql_array_adm->ID."\" />";
                            print "<input type=\"hidden\" name=\"PageNo\" value=\"".$PageNo."\" />";
                            print "<input type=\"hidden\" value=\"".$F_Surname."\" name=\"F_Surname\" />";
                            print "<input type=\"hidden\" value=\"".$F_Organisation."\" name=\"F_Organisation\" />";
                            print "<input type=\"hidden\" value=\"".$F_ICO."\" name=\"F_ICO\" />";
                            print "<input type=\"submit\" value=\"".INV_ZOBRAZIT."\" style=\"width :60px; background-color: ".BUTTON_ON_OUT.";\"
                                    onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                                    onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />";
                          print "</form>";
                    print "</td>";

                    print "<td align=\"right\" width=\"43px\">";
                          print "<form action=\"invoice_print.php\" target=\"_Blank\" method=\"post\">";
                            print "<input type=\"hidden\" name=\"ID\" value=\"".$sql_array_adm->ID."\" />";
                            print "<input type=\"hidden\" value=\"".$F_Surname."\" name=\"F_Surname\">";
                            print "<input type=\"hidden\" value=\"".$F_Organisation."\" NAME=\"F_Organisation\" />";
                            print "<input type=\"hidden\" value=\"".$F_ICO."\" name=\"F_ICO\" />";
                            print "<input type=\"submit\" value=\"".INV_TLAC."\" style=\"width :40px; background-color: ".BUTTON_ON_OUT.";\"
                                    onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                                    onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />";
                          print "</form>";
                    print "</td>";

                    print "<td align=\"right\" width=\"63px\">";
                          print "<form action=\"invoice.php\" target=\"place\" method=\"post\">";
                          print "<input type=\"hidden\" value=\"".$ActualQvantumPage."\" NAME=\"ActualQvantumPage\" />";
                            print "<input type=\"hidden\" name=\"events\" value=\"delete_order\" />";
                            print "<input type=\"hidden\" name=\"roll_show\" value=\"".$roll_show."\" />";
                            print "<input type=\"hidden\" name=\"Ch_ID\" value=\"".$sql_array_adm->ID."\" />";
                            print "<input type=\"hidden\" name=\"PageNo\" value=\"".$PageNo."\" />";
                            print "<input type=\"hidden\" value=\"".$F_Surname."\" name=\"F_Surname\" />";
                            print "<input type=\"hidden\" value=\"".$F_Organisation."\" name=\"F_Organisation\" />";
                            print "<input type=\"hidden\" value=\"".$F_ICO."\" name=\"F_ICO\" />";
                            print "<input type=\"submit\" value=\"".INV_ODSTRANIT."\" style=\"width :60px; background-color: ".BUTTON_ON_OUT.";\"
                                    onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                                    onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />";
                          print "</form>";
                    print "</td></tr>";

            }
            else
            {
                if($ShowAsDetails){
                    if(($counter%2))
                        print "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"98%\" bgcolor=\"".TR_BACKGOUND_COLOR_2."\">";
                    else
                        print "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"98%\" bgcolor=\"".TR_BACKGOUND_COLOR_1."\">";

                    print "<tr><td>";


                    //***********zobrazenie hlavicky faktury********
                    if(($counter%2))
                        print "<table  border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"".TR_BACKGOUND_COLOR_2."\" width=\"800px\" style=\"margin-left=5pt;\">";
                    else
                        print "<table  border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"".TR_BACKGOUND_COLOR_1."\" width=\"800px\" style=\"margin-left=5pt;\">";

                                @$dbResult=mysql_query("SELECT * FROM invoice_heads WHERE ID=".$sql_array_adm->ID);
                                if (!dbResult) {
                                    print INV_CHYBA_PRI_VYHLADAVANI_UDAJOV_STRANKU_NEMOZNO_ZOBRAZIT;
                                    break;
                                }
                                $sql_array_User = mysql_fetch_object($dbResult);
                                //**********************************************************************
                                //zobrazenie udajov o dodavatelovi
                                //**********************************************************************
                                print "<tr><td valign=\"top\">";
                                    print ("<b><u>".INV_DODAVATEL.":</u></b><br />");
                                    $file = fopen("../../address.txt", "r") or die (INV_CHYBA_SUBORU." 'address.txt'!");
                                    while (!feof($file)){
                                            $file_row = fgets($file, 500);
                                            print ($file_row. "<br />");
                                    }
                                    
                                    //sposob dorucenia
                                    print "<br /><br />".INV_SPOSOB_DORUCENIA.":".$sql_array_User->IH_Delivery;
                                    
                            		
                                print "</td>";
                                //**********************************************************************
                                //zobrazenie hlavicky faktury a udajov o odberatelovi
                                //**********************************************************************
                                print "<td valign=\"top\">";
                                	print "<table style=\"width:100%;\">";
                                            print "<tr style=\"border:1px solid black;\">";
                                                    print "<td style=\"border:1px solid black;\">";
                                                            print "
                                                                    <table>
                                                                            <tr>
                                                                                    <td>
                                                                                            ".INV_FAKTURA_CISLO.":
                                                                                    </td>
                                                                                    <td>
                                                                                            ".$sql_array_User->IH_Prefix.$sql_array_User->IH_No."
                                                                                    </td>
                                                                            <tr>
                                                                            </tr>
                                                                                    <td>
                                                                                            ".INV_KONSTANTNY_SYMBOL.":
                                                                                    </td>
                                                                                    <td>
                                                                                            ".$sql_array_User->IH_Constant_Symbol."
                                                                                    </td>
                                                                            </tr>
                                                                    </table>
                                                            ";
                                                    print "</td>"; 
                                            print "</tr>";
                                            print "<tr>";
                                                    print "<td>";                                	
                                                        print "<b><u>".INV_ODBERATEL.":</u></b>";
                                                        if ($sql_array_User->IH_ICO!="")
		                                            print "(".INV_ICO.": ".$sql_array_User->IH_ICO.")<br />";
		                                        else
                                                            print "<br />";
		                                        //vyhladanie udajov v DB
		                                        if ($sql_array_User->IH_Organisation!="")
		                                            print $sql_array_User->IH_Organisation."<br />";
		                                        if ($sql_array_User->IH_Organisation=="")
		                                        	print $sql_array_User->IH_Name." ".$sql_array_User->IH_Surname."<br />";
		                                        print $sql_array_User->IH_Street."<br />";
		                                        print $sql_array_User->IH_PostID." ".$sql_array_User->IH_City."<br />";		                                        
		                                        if ($sql_array_User->IH_DIC!="")
		                                            print INV_DIC.": ".$sql_array_User->IH_DIC."<br />";
		                                        $Order_text = $sql_array_User->IH_Additorial_Text;
		                                        mysql_free_result($dbResult);
                                                    print "</td>"; 
                                            print "</tr>"; 
                                            print "<tr style=\"border:1px solid black;\">";
                                                    print "<td style=\"border:1px solid black;\">";
                                                            print "
                                                                    <table>
                                                                            <tr>
                                                                                    <td>
                                                                                            ".INV_DATUM_VYSTAVENIA.":
                                                                                    </td>														
                                                                                    <td>  
                                                                                            ".date(sttngs_DATE_FORMAT,strtotime($sql_array_User->IH_Create))."
                                                                                    </td>
                                                                            </tr>
                                                                            <tr>
                                                                                    <td>
                                                                                            ".INV_DATUM_SPLATNOSTI.":
                                                                                    </td>
                                                                                    <td>  
                                                                                            ".date(sttngs_DATE_FORMAT,strtotime($sql_array_User->IH_Expiration))."
                                                                                    </td>
                                                                            </tr>
                                                                            <tr>
                                                                                    <td>
                                                                                            ".INV_DATUM_DAN.":
                                                                                    </td>
                                                                                    <td>  
                                                                                            ".date(sttngs_DATE_FORMAT,strtotime($sql_array_User->IH_Tax))."
                                                                                    </td>
                                                                            </tr>
                                                                            <tr>
                                                                                    <td>
                                                                                            ".INV_SPOSOB_PLATBY.":
                                                                                    </td>
                                                                                    <td>  
                                                                                            ".$sql_array_User->IH_Payment_Type."
                                                                                    </td>
                                                                            </tr>
                                                                    </table>
                                                            ";
                                                    print "</td>"; 
                                            print "</tr>";          
		                            print "</table>";
                                print "</td></tr>";
                                //**********************************************************************
                                //zobrazenie tovaru
                                //**********************************************************************
                                print "<tr><td colspan=\"2\">";
                                    print ("<b><u>".INV_FAKTURUJEME_VAM_ZA.":</u></b></br>");
                                print "</td></tr>";
                                print "<tr><td colspan=\"2\">";
                                print "<table width=\"100%\">";
                                if(PAYER_VAT=="YES")
                                    //**********************************************************************
                                    //platca DPH
                                    print "<tr><td><b>".O_KOD."</b></td><td><b>".O_POLOZKA."</b></td><td><b>".O_MJ."</b></td><td><b>".O_CENA_ZA_MJ."</b></td><td><b>".O_DPH."</b></td><td><b>".O_CENA_S_DPH."</b></td><td><b>".O_MNOZSTVO."</b></td><td><b>".O_SPOLU."</b></td></tr>";
                                    //**********************************************************************
                                else
                                    //**********************************************************************
                                    //platca DPH
                                    print "<tr><td><b>".O_KOD."</b></td><td><b>".O_POLOZKA."</b></td><td><b>".O_MJ."</b></td><td><b>".O_CENA_ZA_MJ."</b></td><td><b>".O_MNOZSTVO."</b></td><td><b>".O_SPOLU."</b></td></tr>";
                                    //**********************************************************************
                                
                                
                        $sql_bin= "SELECT * FROM invoice_products WHERE IH_ID=".$sql_array_adm->ID;
                        $bin_source = mysql_query($sql_bin);
                        $TotalSum=0;
                        $TotalEuro=0;
                        while ($sql_array_Prodct = mysql_fetch_object($bin_source))
                        {
                                //urcenie ci sa produt nachadza v tabulke produktov
                                if($sql_array_Prodct->IP_ID != "")
                                        $products_count = mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM products WHERE ID=$sql_array_Prodct->IP_ID"));    
                                else
                                        $products_count[0] = 0;
                          			
                                print "<tr><td>";           
                                        //zobrazenie produktu v objednavke
                                        if($products_count[0] < 1)
                                		print $sql_array_Prodct->IP_Code;
                                	else
										//odkaz na produkt v objednavke
	                                	print "
                                                    <a href=\"javascript:\"
                                                        onclick=\"OpenPage(".$sql_array_Prodct->IP_ID.", 1);\"
                                                        target=\"oa_product_detail\">".$sql_array_Prodct->IP_Code."</a>
										";
                                print "</td>";
								print "<td>";
                                	//zobrazenie produktu v objednavke
					if($products_count[0] < 1)
                                		print $sql_array_Prodct->IP_Name;
                                	else
						//odkaz na produkt v objednavke
	                                	print "
                                                        <a href=\"javascript:\"
                                                            onclick=\"OpenPage(".$sql_array_Prodct->IP_ID.", 1);\"
                                                            target=\"oa_product_detail\">".$sql_array_Prodct->IP_Name."</a>
                                                ";
                                print "</td>";
                                print "<td>";
                                print $sql_array_Prodct->IP_UnitType;
                                print "</td>";
                                print "<td>";
                                print FormatItAsCurrency($sql_array_Prodct->IP_Price);
                                if (file_exists("../../euro.php")) print O_MENA."<br />".FormatItAsCurrency($sql_array_Prodct->IP_Euro).O_SKK_MENA;
                                print "</td>";
                                
                                
                                if(PAYER_VAT=="YES"){
		                        //**********************************************************************
		                        //platca DPH
		                        print "<td>";
		                                print $sql_array_Prodct->IP_DPH;
		                        print "</td>";
		                        print "<td>";
		                                print FormatItAsCurrency(((($sql_array_Prodct->IP_DPH)/100)+1) * $sql_array_Prodct->IP_Price);
		                                if (file_exists("../../euro.php")) print O_MENA."<br />".FormatItAsCurrency(((($sql_array_Prodct->IP_DPH)/100)+1) * $sql_array_Prodct->IP_Euro).O_SKK_MENA;
		                        print "</td>";
		                        //**********************************************************************
		                    }
                                
                                
                                print "<td>";
                                print $sql_array_Prodct->IP_Count;
                                print "</td>";
                                if(PAYER_VAT=="YES"){
		                        //**********************************************************************
		        		//platca DPH
                                	print "<td>";
                                	print FormatItAsCurrency(((($sql_array_Prodct->IP_DPH)/100)+1) * $sql_array_Prodct->IP_Price * $sql_array_Prodct->IP_Count);
                                	if (file_exists("../../euro.php")) print  O_MENA."<br />".FormatItAsCurrency(((($sql_array_Prodct->IP_DPH)/100)+1) * $sql_array_Prodct->IP_Euro * $sql_array_Prodct->IP_Count).O_SKK_MENA;
                                	print "</td>";
                                }
                                else{
                                  	//neplatca DPH
                                	print "<td>";
                                	print FormatItAsCurrency($sql_array_Prodct->IP_Price * $sql_array_Prodct->IP_Count);
                                	if (file_exists("../../euro.php")) print  O_MENA."<br />".FormatItAsCurrency($sql_array_Prodct->IP_Euro * $sql_array_Prodct->IP_Count).O_SKK_MENA;
                                	print "</td>";
                                }
                                
                                print "</tr>"; 

                                if(PAYER_VAT=="YES"){
                                        //**********************************************************************
                                        //platca DPH
	                                $TotalSum+=((($sql_array_Prodct->IP_DPH)/100)+1) * $sql_array_Prodct->IP_Price * $sql_array_Prodct->IP_Count;
	                                if (file_exists("../../euro.php")) $TotalEuro+=((($sql_array_Prodct->IP_DPH)/100)+1) * $sql_array_Prodct->IP_Euro * $sql_array_Prodct->IP_Count;
								}
	                            else{
	                            	//neplatca DPH
	                            	$TotalSum+= $sql_array_Prodct->IP_Price * $sql_array_Prodct->IP_Count;
	                            	if (file_exists("../../euro.php")) $TotalEuro+= $sql_array_Prodct->IP_Euro * $sql_array_Prodct->IP_Count;
	                            }
                        }


                                print "</table>";
                                print "</td></tr>";
                                //**********************************************************************
                                //zobrazenie celkovej sumy
                                //**********************************************************************
                                print "
                                    <tr>
                                            <td style=\"text-align:left; width:250px;\">
                                                    <br />
                                                    $Order_text
                                                    <br />
                                            </td>
                                            <td style=\"text-align:right;\">
				";
                                if(PAYER_VAT=="YES"){
                                    //**********************************************************************
                                    //platca DPH
                                    print ("<br /><b><u>".O_CELKOM.":".RoundIt($TotalSum).O_MENA_S_DPH."</u></b><br /><br />");
                                    if (file_exists("../../euro.php")) print (RoundItEUR($TotalEuro).O_SKK_MENA_S_DPH."<br />");
                                }
                                else{
                                    //neplatca DPH
                                    print "<br /><b><u>".O_CELKOM.":".RoundIt($TotalSum).O_MENA."</u></b><br />";
                                    if (file_exists("../../euro.php")) print RoundItEUR($TotalEuro).O_SKK_MENA."<br />";
                                    print O_NIE_SME_PLATCOVIA_DPH."<br />";			                                	
                                }
                                print "
                                                </td>
                                        </tr>
                                </table>
                                ";


                    //print "</table>";
                    //**********************************************************

                    print "</td><tr>";

                    print "<tr><td>";
                    	print "<br />";
                    	print "<table><tr>";
		                    print "<td align=\"right\" width=\"43px\">";
		                          print "<form action=\"invoice_print.php\" target=\"_Blank\" method=\"post\">";
		                            print "<input type=\"hidden\" name=\"ID\" value=\"".$sql_array_adm->ID."\" />";
		                            print "<input type=\"hidden\" value=\"".$F_Surname."\" name=\"F_Surname\">";
		                            print "<input type=\"hidden\" value=\"".$F_Organisation."\" name=\"F_Organisation\" />";
		                            print "<input type=\"hidden\" value=\"".$F_ICO."\" name=\"F_ICO\" />";
		                            print "<input type=\"submit\" value=\"".INV_TLAC."\" style=\"width :40px; background-color: ".BUTTON_ON_OUT.";\"
			                            onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
			                            onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />";
		                          print "</form>";
		                    print "</td>";
		                    
		                    print "<td align=\"right\" valign=\"bottom\" width=\"83px\">";
		                          print "<form action=\"invoice.php\" target=\"place\" method=\"post\">";
		                          print "<input type=\"hidden\" value=\"".$ActualQvantumPage."\" name=\"ActualQvantumPage\" />";
		                            print "<input type=\"hidden\" name=\"events\" value=\"show_order\" />";
		                            print "<input type=\"hidden\" name=\"roll_show\" value=\"".$roll_show."\" />";
		                            print "<input type=\"hidden\" name=\"Ch_ID\" value=\"".$sql_array_adm->ID."\" />";
		                            print "<input type=\"hidden\" name=\"PageNo\" value=\"".$PageNo."\" />";
		                            print "<input type=\"hidden\" value=\"".$F_Surname."\" name=\"F_Surname\" />";
		                            print "<input type=\"hidden\" value=\"".$F_Organisation."\" name=\"F_Organisation\" />";
		                            print "<input type=\"hidden\" value=\"".$F_ICO."\" name=\"F_ICO\" />";
		                            print "<input type=\"submit\" value=\"".INV_ZRUSIT_NAHLAD."\" style=\"width :120px; background-color: ".BUTTON_ON_OUT.";\"
			                            onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
			                            onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />";
		                          print "</form>";
		                    print "</td>";
		                print "</tr></table>";
                    
                    print "</td></tr>";
                    print "</table>";
                };
            }
            print "</table>";
            $counter++;
        }


        print "<br>";
        PrintLine();

    //**************************************************************************
    //
    //Vytvorenie menu pre vyber zobrazovanej stranky (rozdelenie zobrazovane hotovaru) - ulozene dole
    //
    //**************************************************************************
    if ($F_Surname!="") $sql_psel= "SELECT COUNT(*) FROM invoice_heads WHERE IH_Surname LIKE '%".$F_Surname."%'";
    if ($F_Organisation!="") $sql_psel= "SELECT COUNT(*) FROM invoice_heads WHERE IH_Organisation LIKE '%".$F_Organisation."%'";
    if ($F_ICO!="") $sql_psel= "SELECT COUNT(*) FROM invoice_heads WHERE IH_ICO='".$F_ICO."'";
    if ($F_Surname=="" and $F_Organisation=="" and $F_ICO=="")
            $sql_psel= "SELECT COUNT(*) FROM invoice_heads";
    $sql_array_adm = mysql_fetch_row(mysql_query($sql_psel));
    do{
            if (($sql_array_adm[0]/$ItemsOnPage)<=1) break;
             print"<CENTER><table style=\"position:relative;  top:5px;\"><tr>";

// Podmienka prvej >>>> --------------------------------------------------------------------
      if(($sql_array_adm[0]/$ItemsOnPage>$ShowQvantumPage) and ($ActualQvantumPage-$ShowQvantumPage>=0)){
             print "<td>";
             print "<form  action=\"invoice.php\" target=\"place\" method=\"post\">";
             if($sql_array_adm[0]>$ShowQvantumPage)
               print "<input type=\"submit\" value=\"<<<\"  style=\"width :50px; background-color: ".BUTTON_ON_OUT.";\"
                             onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                             onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />";
               $xxx=$ActualQvantumPage-$ShowQvantumPage;
               $Pagexxx=$xxx;
               print "<input type=\"hidden\" value=\"".$F_Surname."\" name=\"F_Surname\" />";
               print "<input type=\"hidden\" value=\"".$F_Organisation."\" name=\"F_Organisation\" />";
               print "<input type=\"hidden\" value=\"".$F_ICO."\" name=\"F_ICO\" />";
               print "<input type=\"hidden\" value=\"".$Pagexxx."\" name=\"PageNo\" />";
               print "<input type=\"hidden\" value=\"".$xxx."\" name=\"ActualQvantumPage\" />";
               print "<input type=\"hidden\" value=\"".$Path."\" name=\"path\" />";
               print "<input type=\"hidden\" value=\"".$Category_ID."\" name=\"ID\" />";
             print "</form>";
             print "</td>";
             }
 //--------------------------------------------------------------------------------------

//podmienka zvysnych stranok------------------------------------------------------------
          if(($ActualQvantumPage/$ShowQvantumPage)==floor(($sql_array_adm[0]/$ItemsOnPage)/$ShowQvantumPage))
              { if($sql_array_adm[0]%$ItemsOnPage==0)
                    $ShowActualQvantumPage=((($sql_array_adm[0]/$ItemsOnPage)%$ShowQvantumPage));
                else
                    $ShowActualQvantumPage=((($sql_array_adm[0]/$ItemsOnPage)%$ShowQvantumPage)+1);
              }
          else
              {$ShowActualQvantumPage=$ShowQvantumPage;}
 //---------------------------------------------------------------------------------------
      for($i=$ActualQvantumPage;$i<$ActualQvantumPage+$ShowActualQvantumPage;$i++)
    {
      print "<form  action=\"invoice.php\" target=\"place\" method=\"post\">";
          print "<td>";
          $Xi=$i+1;
          if($PageNo==$i)
            print "<input type=\"submit\" value=\"".$Xi."\" name=\"PageNo\"  style=\"width :50px; background-color: ".BUTTON_ON_OVER.";\">";
          else
            print "<input type=\"submit\" value=\"".$Xi."\" name=\"PageNo\" style=\"width :25px; background-color: ".BUTTON_ON_OUT.";\"
                        onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                        onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\"
                    />";
          print "<input type=\"hidden\" value=\"".$F_Surname."\" name=\"F_Surname\">";
          print "<input type=\"hidden\" value=\"".$F_Organisation."\" name=\"F_Organisation\">";
          print "<input type=\"hidden\" value=\"".$F_ICO."\" name=\"F_ICO\">";
          print "<input type=\"hidden\" value=\"1\" name=\"PageQuanter\">";
          print "<input type=\"hidden\" value=\"".$ActualQvantumPage."\" name=\"ActualQvantumPage\">";
          print "<input type=\"hidden\" value=\"".$Path."\" name=\"path\">";
          print "<input type=\"hidden\" value=\"".$Category_ID."\" name=\"ID\">";
          print "</form>";
          print "</td>";
    }

 //podmienka doprednej >>>> -----------------------------------------------------------
if(($sql_array_adm[0]/$ItemsOnPage) > ($ActualQvantumPage+$ShowQvantumPage)){
      print "<td>";
      print "<form  action=\"invoice.php\" target=\"place\" method=\"post\">";
      print "<input type=\"submit\" value=\">>>\"  style=\"width :50px; background-color: ".BUTTON_ON_OUT.";\"
              onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
              onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />";
      $xxx=$ActualQvantumPage+$ShowQvantumPage;
      $Pagexxx=$xxx;
      print "<input type=\"hidden\" value=\"".$F_Surname."\" name=\"F_Surname\" />";
      print "<input type=\"hidden\" value=\"".$F_Organisation."\" name=\"F_Organisation\" />";
      print "<input type=\"hidden\" value=\"".$F_ICO."\" name=\"F_ICO\" />";
      print "<input type=\"hidden\" value=\"".$Pagexxx."\" name=\"PageNo\" />";
      print "<input type=\"hidden\" value=\"".$xxx."\" name=\"ActualQvantumPage\" />";
      print "<input type=\"hidden\" value=\"".$Path."\" name=\"path\" />";
      print "<input type=\"hidden\" value=\"".$Category_ID."\" name=\"ID\" />";
    print "</form>";
    print "</td>";
    }
 //--------------------------------------------------------------------------------------
    print "</tr></table></center>";
            PrintLine();
    }while(false);

    mysql_close();
}
while(false)
?>


</body>
</html>
